//牛客 WY22 Fibonacci数列
//找到该数字前后的两个斐波那契数，两两相减，返回差值小的即可

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n = 0;
    cin >> n;

    int a = 0, b = 1, c = 1;
    while(1)
    {
        a = b;
        b = c;
        c = a + b;
        if(c >= n)
            break;
    }
    int ans = min(n-b, c-n);
    cout << ans << endl;

    return 0;
}